import { _decorator, Component, Node, director, view, ResolutionPolicy, Director, AudioClip } from 'cc';
import { AudioManager } from './AudioManager';
const { ccclass, property } = _decorator;

@ccclass('StartUI')
export class StartUI extends Component {
    @property(AudioClip)
    bgmClip:AudioClip = null;

    protected onLoad(): void {
        director.once(Director.EVENT_AFTER_SCENE_LAUNCH, this.initViewAdapter);
    }
    start() {
       
       // AudioManager.getInstance().playBGM(this.bgmClip);
    }

    update(deltaTime: number) {
        
    }

    // 添加点击 开始游戏 事件 
    public onStartButtonClick()
    {
        director.loadScene("GameScenes"); //切换场景
    }

    // 在游戏启动时调用
    initViewAdapter() {
    // 设置设计分辨率
    view.setDesignResolutionSize(1080, 1920, ResolutionPolicy.SHOW_ALL);
    
    // 根据实际屏幕比例动态调整
    const screenRatio = view.getVisibleSize().width / view.getVisibleSize().height;
    const designRatio = 1080 / 1920;

    if (screenRatio > designRatio) {
        // 宽屏设备（如 428×926），上下留黑边，宽度撑满
        view.setDesignResolutionSize(1080, 1920, ResolutionPolicy.FIXED_WIDTH);
    } else {
        // 窄屏设备，左右留黑边，高度撑满
        view.setDesignResolutionSize(1080, 1920, ResolutionPolicy.FIXED_HEIGHT);
    }
}
}



